package com.hlkj.baojin.config;

import com.hlkj.baojin.constant.BaojinConstant;
import com.hlkj.baojin.constant.request.ConstantInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lzx
 **/

@Configuration
public class CORSConfiguration {
    private static Logger log = LoggerFactory.getLogger(CORSConfiguration.class);


    /**
     * @return
     */
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            /**
             * 添加自定义拦截器
             */
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new ConstantInterceptor()).addPathPatterns(BaojinConstant.REQUEST_URL);
            }

            /**
             * 解决跨域问题
             */
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedHeaders("*")
                        .allowedMethods("*")
                        .allowedOrigins("*");


                //.allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
//                        .allowCredentials(false).maxAge(3600);
            }

            //            /** 这里配置视图解析器 **/
//            void configureViewResolvers(ViewResolverRegistry registry);
//            /** 配置内容裁决的一些选项 **/
//            void configureContentNegotiation(ContentNegotiationConfigurer configurer);
//            /** 视图跳转控制器 **/
//            void addViewControllers(ViewControllerRegistry registry);
//            /** 静态资源处理 **/
//            void addResourceHandlers(ResourceHandlerRegistry registry);
//            /** 默认静态资源处理器 **/
//            void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer);


        };
    }


}
